//
//  SWPresentationController.swift
//  SwiftWB
//
//  Created by 钟清 on 17/3/28.
//  Copyright © 2017年 Zhong Qing. All rights reserved.
//

import UIKit

class SWPresentationController: UIPresentationController {
    
    /// 尺寸
    var presentFrame = CGRectZero
    
    override init(presentedViewController: UIViewController, presentingViewController: UIViewController) {
        super.init(presentedViewController: presentedViewController, presentingViewController: presentingViewController)
    }
    
    /// 设置弹出视图尺寸
    override func containerViewWillLayoutSubviews() {
        
        presentedView()?.frame = presentFrame // CGRect(x: 65, y: 55, width: 200, height: 200)
        containerView?.insertSubview(coverButton, atIndex: 0)
        coverButton.addTarget(self, action: #selector(SWPresentationController.coverButtonClick), forControlEvents: UIControlEvents.TouchUpInside)
    }
    
    // MARK: - Lazy
    private lazy var coverButton : UIButton = {
        let btn = UIButton()
        btn.frame = UIScreen.mainScreen().bounds
        return btn
    }()
    // MARK: - 内部控制方法：点击退出视图
    @objc private func coverButtonClick() {
        presentingViewController.dismissViewControllerAnimated(true, completion: nil)
    }

}
